import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/introduction',
    children: [{
      path: 'introduction',
      name: 'Introduction',
      component: () => import('@/views/introduction/index'),
      meta: { title: '介绍', icon: 'dashboard' }
    }]
  },

  {
    path: '/lol',
    component: Layout,
    redirect: '/lol/LOL_Hero',
    name: 'Example',
    meta: { title: '英雄联盟知识图谱', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'LOL_Hero',
        name: 'LOL_Hero',
        component: () => import('@/views/lol/hero/index'),
        meta: { title: '英雄相关内容', icon: 'table' }
      },
      {
        path: 'LOL_Region',
        name: 'LOL_Region',
        component: () => import('@/views/lol/region/index'),
        meta: { title: '区域相关内容', icon: 'el-icon-s-grid' }
      },
      {
        path: 'LOL_KGQA',
        name: 'LOL_KGQA',
        component: () => import('@/views/lol/KGQA/index'),
        meta: { title: '知识图谱问答', icon: 'tree' }
      }
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  // 根据环境变更路由的前置路径
  base: process.env.NODE_ENV === 'development' ? '' : '/lol_kg',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
